<?php
/**
 * Created by PhpStorm.
 * 商家账户余额操作记录
 * User: caicm
 * Date: 2017/6/22
 * Time: 20:32
 */

namespace WMApi\Model;


use Think\Model;

class WmSellerAccountRecordModel extends Model {

    /**
     * 添加商家账户余额操作记录
     * Created By caicm
     * @param int $seller_id 商家id
     * @param int $store_id 店铺id
     * @param int $type 操作类型（1-提现-支出 2-提现失败-收入 3-结算-收入 4-充值-收入 5-配送服务费-支出 6-配送服务费退回-收入 ）
     * @param int $type_id 关联操作类型表主键(提现-withdraw_record,结算-order_income,充值-recharge_log,配送服务-order_info)
     * @param int $account_type 账户类型（1-支出 2-收入）
     * @param int $money 金额
     * @param string $record_note 记录备注
     * @param int $account_money 账户余额
     * @return mixed
     */
    public function add_record($seller_id=0, $store_id=0, $type=0, $type_id=0, $account_type=0, $money=0, $record_note='', $account_money=0){

        $data = array(
            'seller_id' => $seller_id,
            'store_id' => $store_id,
            'type' => $type,
            'type_id' => $type_id,
            'account_type' => $account_type,
            'money' => $money,
            'record_note' => $record_note,
            'account_money' => $account_money,
            'add_time' => gmtime(),
            'source' => get_source(),
            'version' => get_version()
        );

        return $this->data($data)->add();

    }


    /**
     * 获取商家账户余额操作记录列表
     * Created By caicm
     * @param int $seller_id
     * @param $limit
     * @return mixed
     */
    public function find_record_list($seller_id=0, $limit){

        $where = array(
            'seller_id' => $seller_id
        );

        $field = 'id,type,type_id,account_type,money,account_money,add_time';

        return $this->field($field)->where($where)->order('id desc')->limit($limit)->select();
    }

    /**
     * 获取商家账户余额操作记录数量
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function find_record_count($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->count('id');
    }

}